#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
class Solution
{
public:
    int minlen(vector<int> &nums, int mxnum, int mxcnt)
    {
        int i = 0, j = 0, cnt = 0;
        while (nums[i] != mxnum)
            j = ++i;
        while (j < nums.size() && cnt < mxcnt)
        {
            cnt += (nums[j++] == mxnum ? 1 : 0);
        }
        return j - i;
    }
    int findShortestSubArray(vector<int> &nums)
    {
        map<int, int> hash;
        for (int num : nums)
            hash[num]++;
        int mxcnt = 0, ans = 0x7fffffff;
        for (auto &it : hash)
            mxcnt = max(mxcnt, it.second);
        for (auto &it : hash)
        {
            if (it.second == mxcnt)
                ans = min(ans, minlen(nums, it.first, it.second));
        }
        return ans;
    }
};